package com.companion.companion.controller;

import java.util.List;

import com.companion.companion.domain.User;
import com.companion.companion.service.IUserService;
import com.companion.companion.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 用户信息Controller
 * 
 * @author zly
 * @date 2025-05-06
 */
@CrossOrigin
@RestController
@RequestMapping("/system/user")
public class UserController
{
    @Autowired
    private IUserService userService;

    /**
     * 查询用户信息列表
     */
    @GetMapping("/list")
    public List<User> list(User user)
    {
        return userService.selectUserList(user);
    }

    /**
     * 获取用户信息详细信息
     */
    @GetMapping(value = "/{userId}")
    public User getInfo(@PathVariable("userId") Long userId)
    {
        return userService.selectUserByUserId(userId);
    }

    /**
     * 新增用户信息
     */
    @PostMapping
    public Result add(@RequestBody User user)
    {
        return Result.success(userService.insertUser(user));
    }

    /**
     * 修改用户信息
     */
    @PutMapping
    public int edit(@RequestBody User user)
    {
        return userService.updateUser(user);
    }

    /**
     * 删除用户信息
     */
    @DeleteMapping("/{userIds}")
    public int remove(@PathVariable Long[] userIds)
    {
        return userService.deleteUserByUserIds(userIds);
    }
}
